package com.coocaa.ops.admin.v1.panel.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.coocaa.ops.admin.base.AbstractBizImpl;
import com.coocaa.ops.admin.v1.dmp.biz.impl.DmpRegistryRlsInfoBizImpl;
import com.coocaa.ops.admin.v1.panel.biz.IPanelInfoBiz;
import com.coocaa.ops.admin.v1.panel.mapper.IPanelInfoHistoryMapper;
import com.coocaa.ops.admin.v1.panel.mapper.IPanelInfoMapper;
import com.coocaa.ops.admin.v1.tab.mapper.ITabPanelRlsMapper;
import com.coocaa.ops.common.core.base.enums.ResourceTypeEnum;
import com.coocaa.ops.common.core.base.mapper.IBaseHistoryMapper;
import com.coocaa.ops.common.core.base.mybatis.QueryTemplate;
import com.coocaa.ops.common.core.base.util.BeanCopyUtil;
import com.coocaa.ops.common.core.biz.panel.entity.PanelInfoEntity;
import com.coocaa.ops.common.core.biz.panel.entity.PanelInfoHistoryEntity;
import com.coocaa.ops.common.core.biz.tab.entity.TabPanelRlsEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author bjh
 * @description 板块信息原始表-biz层接口实现
 * @date 2020-06-15 14:40:18
 */
@Service
public class  PanelInfoBizImpl extends AbstractBizImpl<IPanelInfoMapper, PanelInfoEntity> implements  IPanelInfoBiz {
    @Autowired
    private IPanelInfoHistoryMapper thisHistoryMapper;
    @Autowired
    private ITabPanelRlsMapper tabPanelRlsMapper;
    @Autowired
    private DmpRegistryRlsInfoBizImpl dmpRegistryRlsInfoBiz;

    @Override
    public IBaseHistoryMapper getHistoryMapper() {
        return thisHistoryMapper;
    }

    @Override
    public PanelInfoEntity createOriginEntityNewInstance() {
        return new PanelInfoEntity();
    }

    @Override
    public PanelInfoHistoryEntity createHistoryEntityNewInstance() {
    PanelInfoHistoryEntity historyEntity = new PanelInfoHistoryEntity();
        return historyEntity;
    }

    @Override
    public boolean isPanelHasUsed(Integer panelId) {
        QueryTemplate<TabPanelRlsEntity> queryTemplate = QueryTemplate.getEqQueryTemplate("flag", 1);
        queryTemplate.lambda().eq(TabPanelRlsEntity::getPanelId, panelId);
        return tabPanelRlsMapper.selectCount(queryTemplate) > 0 || dmpRegistryRlsInfoBiz.isResourceHasUsed(panelId, ResourceTypeEnum.PANEL.getValue());
    }


}
